<?
class NvControllerform extends NvController{
	
	
	function display()
	{
	$mbuh = JRequest::getVar('task');
		if (empty($mbuh)||$mbuh=='cancel'){
			JRequest::setVar( 'view'  , 'hotel');
			JRequest::setVar( 'edit', false );
			
			parent::display();
		}else{
			JRequest::setVar( 'view'  , 'form');
			JRequest::setVar( 'edit', false );
			
			parent::display();
		}
	}
	
	
	function edit()
	{
		JRequest::setVar( 'view', 'form' );
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

	function save()
	{
		$model = $this->getModel('form');
		$post	= JRequest::get('post');
		$cid	= JRequest::getVar( 'cid', array(0), 'post', 'array' );
		$post['id'] = (int) $cid[0];

		if ($model->store($post)) {
			$msg = JText::_( 'Data Telah Disimpan' );
		} else {
			$msg = JText::_( 'Data tidak bisa disimpan' );
		}

		$this->setRedirect(JRoute::_('index.php?option=com_nv&view=hotel', false), $msg);
	}
	
	function remove()
	  {
	    $cid = JRequest::getVar( 'cid', array(), '', 'array' );
	    $db =& JFactory::getDBO(); 
	   if(count($cid))
	    {
	      $cids = implode( ',', $cid );
	      $query = "DELETE FROM #__hotel WHERE id IN ( $cids )";
	      $db->setQuery( $query );
		  if (!$db->query()) {
	        echo "<script> alert('".$db->getErrorMsg()."'); window.
history.go(-1); </script>\n";
			$msg = JText::_( 'Data Tidak Bisa Dihapus' );
	      }else {
		    $msg = JText::_( 'Data Telah Dihapus' );
		  }
	    }
	    //$this->setRedirect( 'index.php?option=com_nv&view=hotel ');
	    $this->setRedirect(JRoute::_('index.php?option=com_nv&view=hotel', false), $msg);
	  }

}//end of class

?>